/**
 * Project Name:springmvc
 * File Name:SysMgrController.java
 * Package Name:cn.springmvc.controller
 * Date:2016年6月14日下午11:02:38
 * Copyright (c) 2016,  All Rights Reserved.
 *
*/

package cn.springmvc.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import cn.springmvc.model.SysFunction;
import cn.springmvc.model.SysRole;
import cn.springmvc.model.SysRoleFunction;
import cn.springmvc.model.SysUser;
import cn.springmvc.model.SysUserRole;
import cn.springmvc.service.SysServiceI;
import common.CommonStant;

/**
 * ClassName:SysMgrController <br/>
 * Function: 系统管理. <br/>
 * Date: 2016年6月14日 下午11:02:38 <br/>
 * 
 * @author i1093108915@yeah.net
 * @version
 * @since JDK 1.6
 * @see
 */
@Controller
@RequestMapping("/mgrController")
public class SysMgrController extends BaseController {

	@Autowired
	SysServiceI sysService;

	/**
	 * insertUser:(新增用户). <br/>
	 *
	 * @author i1093108915@yeah.net
	 * @param request
	 * @param user
	 * @return
	 * @since JDK 1.6
	 */
	@RequestMapping(value = "insertUser", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView insertUser(HttpServletRequest request, SysUser user) {
		ModelAndView mv = new ModelAndView();
		if (!super.checkOnline(request)) {
			mv.setViewName("oprResult");
			return mv;
		}
		int rtn = sysService.insert(user);
		if (rtn > 0) {
			mv.addObject("oprReulst", CommonStant.OPR_RESUT_SUC);
		} else {
			mv.addObject("oprReulst", CommonStant.OPR_RESULT_FAIL);
		}

		return null;
	}
	
	
	/**
	 * insertRole:(新增角色). <br/>
	 *
	 * @author i1093108915@yeah.net
	 * @param request
	 * @param role
	 * @return
	 * @since JDK 1.6
	 */
	@RequestMapping(value = "insertRole", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView insertRole(HttpServletRequest request, SysRole role) {
		ModelAndView mv = new ModelAndView();
		if (!super.checkOnline(request)) {
			mv.setViewName("oprResult");
			return mv;
		}
		int rtn = sysService.insert(role);
		if (rtn > 0) {
			mv.addObject("oprReulst", CommonStant.OPR_RESUT_SUC);
		} else {
			mv.addObject("oprReulst", CommonStant.OPR_RESULT_FAIL);
		}

		return null;
	}
	
	/**
	 * insertFunction:(新增功能). <br/>
	 *
	 * @author i1093108915@yeah.net
	 * @param request
	 * @param function
	 * @return
	 * @since JDK 1.6
	 */
	@RequestMapping(value = "insertFunction", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView insertFunction(HttpServletRequest request, SysFunction function) {
		ModelAndView mv = new ModelAndView();
		if (!super.checkOnline(request)) {
			mv.setViewName("oprResult");
			return mv;
		}
		int rtn = sysService.insert(function);
		if (rtn > 0) {
			mv.addObject("oprReulst", CommonStant.OPR_RESUT_SUC);
		} else {
			mv.addObject("oprReulst", CommonStant.OPR_RESULT_FAIL);
		}

		return null;
	}
	
	/**
	 * insertUserRole:(用户定角色). <br/>
	 *
	 * @author i1093108915@yeah.net
	 * @param request
	 * @param userRole
	 * @return
	 * @since JDK 1.6
	 */
	@RequestMapping(value = "insertUserRole", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView insertUserRole(HttpServletRequest request, SysUserRole userRole) {
		ModelAndView mv = new ModelAndView();
		if (!super.checkOnline(request)) {
			mv.setViewName("oprResult");
			return mv;
		}
		int rtn = sysService.insert(userRole);
		if (rtn > 0) {
			mv.addObject("oprReulst", CommonStant.OPR_RESUT_SUC);
		} else {
			mv.addObject("oprReulst", CommonStant.OPR_RESULT_FAIL);
		}

		return null;
	}
	
	/**
	 * insertRoleFunction:(角色赋权). <br/>
	 *
	 * @author i1093108915@yeah.net
	 * @param request
	 * @param roleFunction
	 * @return
	 * @since JDK 1.6
	 */
	@RequestMapping(value = "insertRoleFunction", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView insertRoleFunction(HttpServletRequest request, SysRoleFunction roleFunction) {
		ModelAndView mv = new ModelAndView();
		if (!super.checkOnline(request)) {
			mv.setViewName("oprResult");
			return mv;
		}
		int rtn = sysService.insert(roleFunction);
		if (rtn > 0) {
			mv.addObject("oprReulst", CommonStant.OPR_RESUT_SUC);
		} else {
			mv.addObject("oprReulst", CommonStant.OPR_RESULT_FAIL);
		}

		return null;
	}
	
	@RequestMapping(value = "getNavigation", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView getNavigation(HttpServletRequest request, String uid) {
		ModelAndView mv = new ModelAndView();
		if (!super.checkOnline(request)) {
			mv.setViewName("oprResult");
			return mv;
		}
		
//		List funlist = this.sysService.

		return null;
	}
}
